<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Jialeo\LaravelSchemaExtend\Schema;

class CreateCashbookCycleTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('cashbook_cycle', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('shopId')->default(0)->comment('店铺id');
            $table->unsignedInteger('userId')->default(0)->comment('用户id');
            $table->unsignedTinyInteger('cycleType')->default(0)->comment('周期默认0-不重复 1-每天 2-每周 3-每月 4-每季度 5-每年');
            $table->unsignedTinyInteger('type')->default(0)->comment('类型 1-收入 2-支出');
            $table->unsignedTinyInteger('category')->default(0)->comment('分类');
            $table->integer('amount')->default(0)->comment('金额 单位：分');
            $table->unsignedInteger('startTime')->default(0)->comment('开始时间');
            $table->unsignedBigInteger('endTime')->default(0)->comment('结束时间');
            $table->unsignedInteger('nextTime')->default(0)->comment('下次开始时间');
            $table->string('remark', 200)->default('')->comment('备注');
            $table->unsignedTinyInteger('status')->default(0)->comment('状态 1-可执行 2-暂停 3-完成');

            $table->unsignedInteger('isDeleted')->default(0)->comment('是否删除 0 - 正常 1 - 已删除');
            $table->unsignedInteger('createdAt')->default(0)->comment('创建时间');
            $table->unsignedInteger('createdByUid')->default(0)->comment('创建人');
            $table->unsignedInteger('updatedAt')->default(0)->comment('修改时间');
            $table->unsignedInteger('updatedByUid')->default(0)->comment('修改人');
            $table->collation = 'utf8mb4_general_ci';
            $table->index(['shopId'], 'idx_shopId');
            $table->index(['userId'], 'idx_userId');
            $table->index(['startTime'], 'idx_startTime');
            $table->index(['endTime'], 'idx_endTime');
            $table->comment = '记账本周期记录';
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('cashbook_cycle');
    }
}
